package com.webank.wedatasphere.qualitis.response;

import java.io.Serializable;

/**
 * @description: 自定义统一返回json格式
 * @author: GuoTong
 * @createTime: 2024-01-25 16:07
 * @since JDK 1.8 OR 11
 **/

@SuppressWarnings("all")
public class Resp<T> implements Serializable {
    //状态码
    private int code;

    //提示信息
    private String msg;

    //返回的数据
    private T data;

    private long count;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public Resp(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Resp() {
    }

    public Resp(int code, String msg, T data, long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    public static <T> Resp<T> OkPage(String msg, T data, long count) {
        return new Resp<T>(200, msg, data, count);
    }
    public static <T> Resp<T> OkPage(T data, long count) {
        return new Resp<T>(200, "Success", data, count);
    }

    public static <T> Resp<T> OkPageLayUI(T data, long count) {
        return new Resp<T>(0, "Success", data, count);
    }
    /**
     * Description:常用返回数据抽离
     */
    public static <T> Resp<T> Ok(String msg, T data) {
        return new Resp<T>(200, msg, data);
    }

    public static <T> Resp<T> error(String errorMsg, T data) {
        return new Resp<T>(500, errorMsg, data);
    }

    public static <T> Resp<T> error(String errorMsg) {
        return new Resp<T>(500, errorMsg, null);
    }

    public static <T> Resp<T> Ok(T data) {
        return new Resp<T>(200, "Success", data);
    }

    public static <T> Resp<T> Ok() {
        return new Resp<T>(200, "Success", null);
    }
}
